// index.js
// 获取应用实例
import {
  config
} from "../../config"
const app = getApp()

Page({
  data: {

  },
  goJoin() {
    // wx.navigateTo({
    //   url: '../checkpoint/index'
    // })
    var userInfo = wx.getStorageSync('userInfo')
    if (userInfo === '') {
      this.getUserProfile()
    } else {
      const openId = wx.getStorageSync('openid')
      wx.request({
        url: `${config.api_blink_url}/redbull/question/user?openid=${openId}`,
        method: "get",
        header: {
          'content-type': 'application/json'
        },
        success: (res) => {
          if (res.data.code === 1) {
            wx.navigateTo({
              url: '../questonList/index'
            })
          }else {
            wx.showToast({
              title: '您已经参加过线上答题',
              icon: 'none',
              duration: 2000 //持续的时间
            })
          }
        }
      })
      console.log(userInfo)
    }
  },
  getUserProfile() {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '获取头像', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        wx.setStorageSync('userInfo', res.userInfo)
        wx.navigateTo({
          url: '../questonList/index'
        })
      }
    })
  },
  onLoad() {},
  onReady() {
    console.log(app.globalData)
  }
})